package xc.com.course.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import xc.com.common.Result;
import xc.com.common.StatusCode;
import xc.com.course.domain.CourseMarket;
import xc.com.course.mapper.CourseMarketMapper;
import xc.com.course.service.CourseMarketService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhuolizhong
 * @since 2021-06-03
 */
@Service
public class CourseMarketServiceImpl extends ServiceImpl<CourseMarketMapper, CourseMarket> implements CourseMarketService {

    @Autowired
    private  CourseMarketMapper courseMarketMapper;
    @Override
    public Result addCourseMarket(CourseMarket courseMarket) {
        int i = courseMarketMapper.insert(courseMarket);
        if(i>0){
       return  new Result(true, StatusCode.OK,"添加成功");
        }
        return  new Result(false, StatusCode.REMOTE_ERROR,"添加失败");
    }

    @Override
    public CourseMarket selectByCourseId(String courseId) {
        return courseMarketMapper.selectById(courseId);
    }

    @Override
    public Result updateCourseMarket(CourseMarket courseMarket) {
        System.out.println(courseMarket);
        if(courseMarket.getPrice()==null){
            courseMarket.setPrice(0.0f);
        }
        int i = courseMarketMapper.updateById(courseMarket);
        if(i>0){
            return  new Result(true, StatusCode.OK,"修改成功！");
        }
        return  new Result(false, StatusCode.REMOTE_ERROR,"修改失败");
    }
}
